#ifndef __RCO_RCOIODEVICE_H__
#define __RCO_RCOIODEVICE_H__

#include <QMutex>
#include <QPair>
#include <QFile>
#include <QTcpSocket>
#include "rcocore_global.h"
#include "cmdparser.h"
#include "rcodef/rcointerface.h"

namespace rco
{

class RcoIODevice
	: public QTcpSocket
{
	Q_OBJECT
public:
	RcoIODevice(QObject* parent = nullptr);
	bool IsCommandFinished() const;
	bool SetCommandState(bool bFin);

	void GetKey();
	void ReleaseKey();

	void SetOutputter(CommandOutputter co);
	qint64 Write(const RcoCommandHead* pRcoCmd, const RcoBuffer* pBytes);

protected slots:
	void Read();

signals:
	void BufferReady(const RcoCommandHead& rcoCmdHead, RcoBuffer& content, RcoIODevice* who);

protected:
	QByteArray		 m_dataBlock;
	QMutex			 m_key;
	bool			 m_bCmdFin;
	qint32			 m_totalSize;
	CommandOutputter m_fnOutter;
};

QDataStream& operator<<(QDataStream& stream, const RcoBuffer& buffer);
QDataStream& operator>>(QDataStream& stream, RcoBuffer& buffer);

};

#endif // __RCO_RCOIODEVICE_H__